package com.dehui.traders.ui.market.rank;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.widget.TextView;

import com.dehui.traders.R;
import com.dehui.traders.bean.PlateListBean;
import com.dehui.traders.widgets.BaseViewHolder;
import com.dehui.traders.widgets.CommonAdapter;

import java.util.List;
import me.goldze.mvvmhabit.utils.Utils;

public class RankItemAdapter extends CommonAdapter<PlateListBean.PlateData>{

    private final String typeCode;

    public RankItemAdapter(Context context, List<PlateListBean.PlateData> mDatas, String typeCode) {
        super(context, mDatas, R.layout.list_item_rank_market_item);
        this.typeCode = typeCode;
    }

    @Override
    public void convert(BaseViewHolder helper, PlateListBean.PlateData item, int position) {

        TextView tvName = helper.getView(R.id.tv_name);
        TextView tvCode = helper.getView(R.id.tv_code);
        TextView tvNews = helper.getView(R.id.tv_news);
        TextView tvRate = helper.getView(R.id.tv_rate);

        tvName.setText(item.name);
        tvCode.setText(item.code.substring(2));
        tvNews.setText(String.valueOf(item.closePrice));
        tvRate.setText(Utils.StringToString(item.changeRate) + "%");

        if ("up".equals(typeCode)){
            tvRate.setTextColor(ContextCompat.getColor(mContext,R.color.red));
        }else if ("down".equals(typeCode)){
            tvRate.setTextColor(ContextCompat.getColor(mContext,R.color.green));
        }

    }
}
